﻿using System.IO;

namespace Rosetta.Default.AddIns.IO
{
    public sealed class FileInputter : Inputter
    {
        #region Fields

        private FileInfo value;

        #endregion

        #region Constructors

        public FileInputter()
            : base("File Inputter")
        {
            Category = "IO";
            ContextType = typeof(FileInfo);

            Add<byte[]>("GetBytes", GetBytes);
            Add<FileInfo>("GetFile", GetFile);
            Add<string[]>("GetLines", GetLines);
            Add<string>("GetText", GetText);
        }

        #endregion

        #region Public Methods

        public override void UseContext(object context)
        {
            value = context as FileInfo;
        }

        #endregion

        #region Private Methods

        private byte[] GetBytes()
        {
            return File.ReadAllBytes(value.FullName);
        }

        private FileInfo GetFile()
        {
            return value;
        }

        private string[] GetLines()
        {
            return File.ReadAllLines(value.FullName);
        }

        private string GetText()
        {
            return File.ReadAllText(value.FullName);
        }

        #endregion
    }
}